<?php
namespace App\Repositories\Main;

use App\Models\Main\CompanyContractModel;
use App\Repositories\BaseRepository;

class ComContractRepository extends BaseRepository
{
    protected $repository;

    public function __construct()
    {
        $this->repository = new CompanyContractModel();
    }

    public function getAdminIndex($baleId)
    {
        $query = $this->repository;
        if ($baleId) {
            $query = $query->where('bale',$baleId);
        }
        $models = $query->paginate(10);
        $models->limit = 10;
        return $models;
    }

    public function setAdd($data)
    {
        $data['created_at'] = time();
        return $this->repository->insertGetId($data);
    }

    public function setModify($data,$orderId)
    {
        $data['updated_at'] = time();
        return $this->repository->where('bale',$orderId)
            ->update($data);
    }

    public function getShowOne($id)
    {
        return $this->repository->where('id',$id)->first();
    }

    public function getOneByBale($baleId)
    {
        return $this->repository
            ->where('bale',$baleId)
            ->first();
    }
}